<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class OpenStruct - ostruct: Ruby Standard Library Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0.preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#class-OpenStruct-label-Examples">Examples</a>
    <li><a href="#class-OpenStruct-label-Caveats">Caveats</a>
  </ul>
</div>


    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link">Object
</div>

        
        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-c-new">::new</a>
    <li ><a href="#method-i-3D-3D">#==</a>
    <li ><a href="#method-i-5B-5D">#[]</a>
    <li ><a href="#method-i-5B-5D-3D">#[]=</a>
    <li ><a href="#method-i-delete_field">#delete_field</a>
    <li ><a href="#method-i-dig">#dig</a>
    <li ><a href="#method-i-each_pair">#each_pair</a>
    <li ><a href="#method-i-eql-3F">#eql?</a>
    <li class="calls-super" ><a href="#method-i-freeze">#freeze</a>
    <li ><a href="#method-i-inspect">#inspect</a>
    <li ><a href="#method-i-set_ostruct_member_value-21">#set_ostruct_member_value!</a>
    <li ><a href="#method-i-to_h">#to_h</a>
    <li ><a href="#method-i-to_s">#to_s</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-OpenStruct">
    <h1 id="class-OpenStruct" class="class">
      class OpenStruct
    </h1>

    <section class="description">
    
<p>An <a href="OpenStruct.html"><code>OpenStruct</code></a> is a data structure, similar to a Hash, that allows the definition of arbitrary attributes with their accompanying values. This is accomplished by using Ruby’s metaprogramming to define methods on the class itself.</p>

<h2 id="class-OpenStruct-label-Examples">Examples<span><a href="#class-OpenStruct-label-Examples">&para;</a> <a href="#top">&uarr;</a></span></h2>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&quot;ostruct&quot;</span>

<span class="ruby-identifier">person</span> = <span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">person</span>.<span class="ruby-identifier">name</span> = <span class="ruby-string">&quot;John Smith&quot;</span>
<span class="ruby-identifier">person</span>.<span class="ruby-identifier">age</span>  = <span class="ruby-value">70</span>

<span class="ruby-identifier">person</span>.<span class="ruby-identifier">name</span>      <span class="ruby-comment"># =&gt; &quot;John Smith&quot;</span>
<span class="ruby-identifier">person</span>.<span class="ruby-identifier">age</span>       <span class="ruby-comment"># =&gt; 70</span>
<span class="ruby-identifier">person</span>.<span class="ruby-identifier">address</span>   <span class="ruby-comment"># =&gt; nil</span>
</pre>

<p>An <a href="OpenStruct.html"><code>OpenStruct</code></a> employs a Hash internally to store the attributes and values and can even be initialized with one:</p>

<pre class="ruby"><span class="ruby-identifier">australia</span> = <span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:country</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;Australia&quot;</span>, <span class="ruby-value">:capital</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;Canberra&quot;</span>)
  <span class="ruby-comment"># =&gt; #&lt;OpenStruct country=&quot;Australia&quot;, capital=&quot;Canberra&quot;&gt;</span>
</pre>

<p>Hash keys with spaces or characters that could normally not be used for method calls (e.g. <code>()[]*</code>) will not be immediately available on the <a href="OpenStruct.html"><code>OpenStruct</code></a> object as a method for retrieval or assignment, but can still be reached through the Object#send method or using [].</p>

<pre class="ruby"><span class="ruby-identifier">measurements</span> = <span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;length (in inches)&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">24</span>)
<span class="ruby-identifier">measurements</span>[<span class="ruby-value">:&quot;length (in inches)&quot;</span>]       <span class="ruby-comment"># =&gt; 24</span>
<span class="ruby-identifier">measurements</span>.<span class="ruby-identifier">send</span>(<span class="ruby-string">&quot;length (in inches)&quot;</span>)   <span class="ruby-comment"># =&gt; 24</span>

<span class="ruby-identifier">message</span> = <span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:queued?</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">message</span>.<span class="ruby-identifier">queued?</span>                           <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">message</span>.<span class="ruby-identifier">send</span>(<span class="ruby-string">&quot;queued?=&quot;</span>, <span class="ruby-keyword">false</span>)
<span class="ruby-identifier">message</span>.<span class="ruby-identifier">queued?</span>                           <span class="ruby-comment"># =&gt; false</span>
</pre>

<p>Removing the presence of an attribute requires the execution of the <a href="OpenStruct.html#method-i-delete_field"><code>delete_field</code></a> method as setting the property value to <code>nil</code> will not remove the attribute.</p>

<pre class="ruby"><span class="ruby-identifier">first_pet</span>  = <span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;Rowdy&quot;</span>, <span class="ruby-value">:owner</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;John Smith&quot;</span>)
<span class="ruby-identifier">second_pet</span> = <span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;Rowdy&quot;</span>)

<span class="ruby-identifier">first_pet</span>.<span class="ruby-identifier">owner</span> = <span class="ruby-keyword">nil</span>
<span class="ruby-identifier">first_pet</span>                 <span class="ruby-comment"># =&gt; #&lt;OpenStruct name=&quot;Rowdy&quot;, owner=nil&gt;</span>
<span class="ruby-identifier">first_pet</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">second_pet</span>   <span class="ruby-comment"># =&gt; false</span>

<span class="ruby-identifier">first_pet</span>.<span class="ruby-identifier">delete_field</span>(<span class="ruby-value">:owner</span>)
<span class="ruby-identifier">first_pet</span>                 <span class="ruby-comment"># =&gt; #&lt;OpenStruct name=&quot;Rowdy&quot;&gt;</span>
<span class="ruby-identifier">first_pet</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">second_pet</span>   <span class="ruby-comment"># =&gt; true</span>
</pre>

<p>Ractor compatibility: A frozen <a href="OpenStruct.html"><code>OpenStruct</code></a> with shareable values is itself shareable.</p>

<h2 id="class-OpenStruct-label-Caveats">Caveats<span><a href="#class-OpenStruct-label-Caveats">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>An <a href="OpenStruct.html"><code>OpenStruct</code></a> utilizes Ruby’s method lookup structure to find and define the necessary methods for properties. This is accomplished through the methods method_missing and define_singleton_method.</p>

<p>This should be a consideration if there is a concern about the performance of the objects that are created, as there is much more overhead in the setting of these properties compared to using a Hash or a Struct. Creating an open struct from a small Hash and accessing a few of the entries can be 200 times slower than accessing the hash directly.</p>

<p>This is a potential security issue; building <a href="OpenStruct.html"><code>OpenStruct</code></a> from untrusted user data (e.g. JSON web request) may be susceptible to a “symbol denial of service” attack since the keys create methods and names of methods are never garbage collected.</p>

<p>This may also be the source of incompatibilities between Ruby versions:</p>

<pre class="ruby"><span class="ruby-identifier">o</span> = <span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">o</span>.<span class="ruby-identifier">then</span> <span class="ruby-comment"># =&gt; nil in Ruby &lt; 2.6, enumerator for Ruby &gt;= 2.6</span>
</pre>

<p>Builtin methods may be overwritten this way, which may be a source of bugs or security issues:</p>

<pre class="ruby"><span class="ruby-identifier">o</span> = <span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>
<span class="ruby-identifier">o</span>.<span class="ruby-identifier">methods</span> <span class="ruby-comment"># =&gt; [:to_h, :marshal_load, :marshal_dump, :each_pair, ...</span>
<span class="ruby-identifier">o</span>.<span class="ruby-identifier">methods</span> = [<span class="ruby-value">:foo</span>, <span class="ruby-value">:bar</span>]
<span class="ruby-identifier">o</span>.<span class="ruby-identifier">methods</span> <span class="ruby-comment"># =&gt; [:foo, :bar]</span>
</pre>

<p>To help remedy clashes, <a href="OpenStruct.html"><code>OpenStruct</code></a> uses only protected/private methods ending with <code>!</code> and defines aliases for builtin public methods by adding a <code>!</code>:</p>

<pre class="ruby"><span class="ruby-identifier">o</span> = <span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">make:</span> <span class="ruby-string">&#39;Bentley&#39;</span>, <span class="ruby-value">class:</span> <span class="ruby-value">:luxury</span>)
<span class="ruby-identifier">o</span>.<span class="ruby-identifier">class</span> <span class="ruby-comment"># =&gt; :luxury</span>
<span class="ruby-identifier">o</span>.<span class="ruby-identifier">class!</span> <span class="ruby-comment"># =&gt; OpenStruct</span>
</pre>

<p>It is recommended (but not enforced) to not use fields ending in <code>!</code>; Note that a subclass’ methods may not be overwritten, nor can OpenStruct’s own methods ending with <code>!</code>.</p>

<p>For all these reasons, consider not using <a href="OpenStruct.html"><code>OpenStruct</code></a> at all.</p>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">


      <section class="constants-list">
      <header>
      <h3>Constants</h3>
      </header>
      <dl>
          <dt id="VERSION">VERSION
          <dd>
        </dl>
        </section>



                <section id="public-class-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Class Methods</h3>
                </header>

                  <div id="method-c-new" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">new</span><span
                                class="method-args">(hash=nil)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Creates a new <a href="OpenStruct.html"><code>OpenStruct</code></a> object.  By default, the resulting <a href="OpenStruct.html"><code>OpenStruct</code></a> object will have no attributes.</p>

<p>The optional <code>hash</code>, if given, will generate attributes and values (can be a Hash, an <a href="OpenStruct.html"><code>OpenStruct</code></a> or a Struct). For example:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&quot;ostruct&quot;</span>
<span class="ruby-identifier">hash</span> = { <span class="ruby-string">&quot;country&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;Australia&quot;</span>, <span class="ruby-value">:capital</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;Canberra&quot;</span> }
<span class="ruby-identifier">data</span> = <span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">hash</span>)

<span class="ruby-identifier">data</span>   <span class="ruby-comment"># =&gt; #&lt;OpenStruct country=&quot;Australia&quot;, capital=&quot;Canberra&quot;&gt;</span>
</pre>

                              <div class="method-source-code" id="new-source">
            <pre><span class="ruby-comment"># File ostruct.rb, line 126</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-identifier">hash</span>=<span class="ruby-keyword">nil</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">hash</span>
    <span class="ruby-identifier">update_to_values!</span>(<span class="ruby-identifier">hash</span>)
  <span class="ruby-keyword">else</span>
    <span class="ruby-ivar">@table</span> = {}
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                          </section>

                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-3D-3D" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">==</span><span
                                class="method-args">(other)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Compares this object and <code>other</code> for equality.  An <a href="OpenStruct.html"><code>OpenStruct</code></a> is equal to <code>other</code> when <code>other</code> is an <a href="OpenStruct.html"><code>OpenStruct</code></a> and the two objects’ Hash tables are equal.</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&quot;ostruct&quot;</span>
<span class="ruby-identifier">first_pet</span>  = <span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;name&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;Rowdy&quot;</span>)
<span class="ruby-identifier">second_pet</span> = <span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">:name</span>  <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;Rowdy&quot;</span>)
<span class="ruby-identifier">third_pet</span>  = <span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;name&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;Rowdy&quot;</span>, <span class="ruby-value">:age</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-keyword">nil</span>)

<span class="ruby-identifier">first_pet</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">second_pet</span>   <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-identifier">first_pet</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">third_pet</span>    <span class="ruby-comment"># =&gt; false</span>
</pre>

                              <div class="method-source-code" id="3D-3D-source">
            <pre><span class="ruby-comment"># File ostruct.rb, line 411</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">==</span>(<span class="ruby-identifier">other</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">OpenStruct</span>)
  <span class="ruby-ivar">@table</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">table!</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-5B-5D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          ostruct[name]  &rarr; object
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the value of an attribute, or <code>nil</code> if there is no such attribute.</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&quot;ostruct&quot;</span>
<span class="ruby-identifier">person</span> = <span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;name&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;John Smith&quot;</span>, <span class="ruby-string">&quot;age&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">70</span>)
<span class="ruby-identifier">person</span>[<span class="ruby-value">:age</span>]   <span class="ruby-comment"># =&gt; 70, same as person.age</span>
</pre>

                              <div class="method-source-code" id="5B-5D-source">
            <pre><span class="ruby-comment"># File ostruct.rb, line 291</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">[]</span>(<span class="ruby-identifier">name</span>)
  <span class="ruby-ivar">@table</span>[<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>]
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-5B-5D-3D" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          ostruct[name] = obj  &rarr; obj
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Sets the value of an attribute.</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&quot;ostruct&quot;</span>
<span class="ruby-identifier">person</span> = <span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;name&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;John Smith&quot;</span>, <span class="ruby-string">&quot;age&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">70</span>)
<span class="ruby-identifier">person</span>[<span class="ruby-value">:age</span>] = <span class="ruby-value">42</span>   <span class="ruby-comment"># equivalent to person.age = 42</span>
<span class="ruby-identifier">person</span>.<span class="ruby-identifier">age</span>          <span class="ruby-comment"># =&gt; 42</span>
</pre>

                              <div class="method-source-code" id="5B-5D-3D-source">
            <pre><span class="ruby-comment"># File ostruct.rb, line 306</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">[]=</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">value</span>)
  <span class="ruby-identifier">name</span> = <span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>
  <span class="ruby-identifier">new_ostruct_member!</span>(<span class="ruby-identifier">name</span>)
  <span class="ruby-ivar">@table</span>[<span class="ruby-identifier">name</span>] = <span class="ruby-identifier">value</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="OpenStruct.html#method-i-set_ostruct_member_value-21">set_ostruct_member_value!</a>
                            </div>

                          </div>

                  <div id="method-i-delete_field" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">delete_field</span><span
                                class="method-args">(name) { || ... }</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Removes the named field from the object and returns the value the field contained if it was defined. You may optionally provide a block. If the field is not defined, the result of the block is returned, or a NameError is raised if no block was given.</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&quot;ostruct&quot;</span>

<span class="ruby-identifier">person</span> = <span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">name:</span> <span class="ruby-string">&quot;John&quot;</span>, <span class="ruby-value">age:</span> <span class="ruby-value">70</span>, <span class="ruby-value">pension:</span> <span class="ruby-value">300</span>)

<span class="ruby-identifier">person</span>.<span class="ruby-identifier">delete_field!</span>(<span class="ruby-string">&quot;age&quot;</span>)  <span class="ruby-comment"># =&gt; 70</span>
<span class="ruby-identifier">person</span>                       <span class="ruby-comment"># =&gt; #&lt;OpenStruct name=&quot;John&quot;, pension=300&gt;</span>
</pre>

<p>Setting the value to <code>nil</code> will not remove the attribute:</p>

<pre class="ruby"><span class="ruby-identifier">person</span>.<span class="ruby-identifier">pension</span> = <span class="ruby-keyword">nil</span>
<span class="ruby-identifier">person</span>                 <span class="ruby-comment"># =&gt; #&lt;OpenStruct name=&quot;John&quot;, pension=nil&gt;</span>

<span class="ruby-identifier">person</span>.<span class="ruby-identifier">delete_field</span>(<span class="ruby-string">&#39;number&#39;</span>)  <span class="ruby-comment"># =&gt; NameError</span>

<span class="ruby-identifier">person</span>.<span class="ruby-identifier">delete_field</span>(<span class="ruby-string">&#39;number&#39;</span>) { <span class="ruby-value">8675_309</span> } <span class="ruby-comment"># =&gt; 8675309</span>
</pre>

                              <div class="method-source-code" id="delete_field-source">
            <pre><span class="ruby-comment"># File ostruct.rb, line 359</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">delete_field</span>(<span class="ruby-identifier">name</span>, <span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
  <span class="ruby-identifier">sym</span> = <span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>
  <span class="ruby-keyword">begin</span>
    <span class="ruby-identifier">singleton_class</span>.<span class="ruby-identifier">remove_method</span>(<span class="ruby-identifier">sym</span>, <span class="ruby-node">&quot;#{sym}=&quot;</span>)
  <span class="ruby-keyword">rescue</span> <span class="ruby-constant">NameError</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">sym</span>) <span class="ruby-keyword">do</span>
    <span class="ruby-keyword">return</span> <span class="ruby-keyword">yield</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">block</span>
    <span class="ruby-identifier">raise!</span> <span class="ruby-constant">NameError</span>.<span class="ruby-identifier">new</span>(<span class="ruby-node">&quot;no field `#{sym}&#39; in #{self}&quot;</span>, <span class="ruby-identifier">sym</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-dig" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          dig(name, *identifiers) &rarr; object
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Finds and returns the object in nested objects that is specified by <code>name</code> and <code>identifiers</code>. The nested objects may be instances of various classes. See Dig Methods.</p>

<p>Examples:</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&quot;ostruct&quot;</span>
<span class="ruby-identifier">address</span> = <span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;city&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;Anytown NC&quot;</span>, <span class="ruby-string">&quot;zip&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">12345</span>)
<span class="ruby-identifier">person</span>  = <span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;name&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;John Smith&quot;</span>, <span class="ruby-string">&quot;address&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-identifier">address</span>)
<span class="ruby-identifier">person</span>.<span class="ruby-identifier">dig</span>(<span class="ruby-value">:address</span>, <span class="ruby-string">&quot;zip&quot;</span>) <span class="ruby-comment"># =&gt; 12345</span>
<span class="ruby-identifier">person</span>.<span class="ruby-identifier">dig</span>(<span class="ruby-value">:business_address</span>, <span class="ruby-string">&quot;zip&quot;</span>) <span class="ruby-comment"># =&gt; nil</span>
</pre>

                              <div class="method-source-code" id="dig-source">
            <pre><span class="ruby-comment"># File ostruct.rb, line 328</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">dig</span>(<span class="ruby-identifier">name</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">names</span>)
  <span class="ruby-keyword">begin</span>
    <span class="ruby-identifier">name</span> = <span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>
  <span class="ruby-keyword">rescue</span> <span class="ruby-constant">NoMethodError</span>
    <span class="ruby-identifier">raise!</span> <span class="ruby-constant">TypeError</span>, <span class="ruby-node">&quot;#{name} is not a symbol nor a string&quot;</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">dig</span>(<span class="ruby-identifier">name</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">names</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-each_pair" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          each_pair {|name, value| block }  &rarr; ostruct
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          each_pair                         &rarr; Enumerator
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Yields all attributes (as symbols) along with the corresponding values or returns an enumerator if no block is given.</p>

<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">&quot;ostruct&quot;</span>
<span class="ruby-identifier">data</span> = <span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&quot;country&quot;</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;Australia&quot;</span>, <span class="ruby-value">:capital</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-string">&quot;Canberra&quot;</span>)
<span class="ruby-identifier">data</span>.<span class="ruby-identifier">each_pair</span>.<span class="ruby-identifier">to_a</span>   <span class="ruby-comment"># =&gt; [[:country, &quot;Australia&quot;], [:capital, &quot;Canberra&quot;]]</span>
</pre>

                              <div class="method-source-code" id="each_pair-source">
            <pre><span class="ruby-comment"># File ostruct.rb, line 199</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">each_pair</span>
  <span class="ruby-keyword">return</span> <span class="ruby-identifier">to_enum</span>(<span class="ruby-identifier">__method__</span>) { <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">size</span> } <span class="ruby-keyword">unless</span> <span class="ruby-keyword">defined?</span>(<span class="ruby-keyword">yield</span>)
  <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">each_pair</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">p</span><span class="ruby-operator">|</span> <span class="ruby-keyword">yield</span> <span class="ruby-identifier">p</span>}
  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-eql-3F" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">eql?</span><span
                                class="method-args">(other)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Compares this object and <code>other</code> for equality.  An <a href="OpenStruct.html"><code>OpenStruct</code></a> is eql? to <code>other</code> when <code>other</code> is an <a href="OpenStruct.html"><code>OpenStruct</code></a> and the two objects’ Hash tables are eql?.</p>

                              <div class="method-source-code" id="eql-3F-source">
            <pre><span class="ruby-comment"># File ostruct.rb, line 421</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">eql?</span>(<span class="ruby-identifier">other</span>)
  <span class="ruby-keyword">return</span> <span class="ruby-keyword">false</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">kind_of?</span>(<span class="ruby-constant">OpenStruct</span>)
  <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">eql?</span>(<span class="ruby-identifier">other</span>.<span class="ruby-identifier">table!</span>)
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-freeze" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">freeze</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              
                                <div class="method-calls-super">
                                  Calls superclass method
                                  
                              </div>

                              <div class="method-source-code" id="freeze-source">
            <pre><span class="ruby-comment"># File ostruct.rb, line 257</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">freeze</span>
  <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">freeze</span>
  <span class="ruby-keyword">super</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-inspect" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">inspect</span><span
                                class="method-args">()</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a string containing a detailed summary of the keys and values.</p>

                              <div class="method-source-code" id="inspect-source">
            <pre><span class="ruby-comment"># File ostruct.rb, line 376</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">inspect</span>
  <span class="ruby-identifier">ids</span> = (<span class="ruby-constant">Thread</span>.<span class="ruby-identifier">current</span>[<span class="ruby-constant">InspectKey</span>] <span class="ruby-operator">||=</span> [])
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">ids</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">object_id</span>)
    <span class="ruby-identifier">detail</span> = <span class="ruby-string">&#39; ...&#39;</span>
  <span class="ruby-keyword">else</span>
    <span class="ruby-identifier">ids</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">object_id</span>
    <span class="ruby-keyword">begin</span>
      <span class="ruby-identifier">detail</span> = <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">map</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">value</span><span class="ruby-operator">|</span>
        <span class="ruby-node">&quot; #{key}=#{value.inspect}&quot;</span>
      <span class="ruby-keyword">end</span>.<span class="ruby-identifier">join</span>(<span class="ruby-string">&#39;,&#39;</span>)
    <span class="ruby-keyword">ensure</span>
      <span class="ruby-identifier">ids</span>.<span class="ruby-identifier">pop</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">end</span>
  [<span class="ruby-string">&#39;#&lt;&#39;</span>, <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class!</span>, <span class="ruby-identifier">detail</span>, <span class="ruby-string">&#39;&gt;&#39;</span>].<span class="ruby-identifier">join</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="OpenStruct.html#method-i-to_s">to_s</a>
                            </div>

                          </div>

                  <div id="method-i-to_h" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">to_h</span><span
                                class="method-args">(&amp;block)</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              

                              <div class="method-source-code" id="to_h-source">
            <pre><span class="ruby-comment"># File ostruct.rb, line 170</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_h</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
  <span class="ruby-keyword">if</span> <span class="ruby-identifier">block</span>
    <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">to_h</span>(<span class="ruby-operator">&amp;</span><span class="ruby-identifier">block</span>)
  <span class="ruby-keyword">else</span>
    <span class="ruby-ivar">@table</span>.<span class="ruby-identifier">dup</span>
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_s" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">to_s</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="OpenStruct.html#method-i-inspect">inspect</a>
                            </div>
                          </div>

                          </section>

                <section id="private-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Private Instance Methods</h3>
                </header>

                  <div id="method-i-set_ostruct_member_value-21" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">set_ostruct_member_value!</span><span
                                class="method-args">(name, value)</span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="OpenStruct.html#method-i-5B-5D-3D">[]=</a>
                            </div>
                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is a service of <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>, purveyors of fine <a href='https://jamesbritt.bandcamp.com/'>dance noise</a></p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

